package de.IIIfeed.MoneyPlanner;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;

import junit.framework.TestCase;
import android.util.Log;

public class TestMoneyPlan extends TestCase {
	
	public TestMoneyPlan(){
	}
	
	private MoneyPlan mp;

	public void setUp() throws Exception {
		super.setUp();
	}

	public void testOnce() throws Exception {
		ArrayList<Item> items = new ArrayList<Item>();
		long oneDay = (long) 1000.0 * 60 * 60 * 24;
		long today = System.currentTimeMillis();
		Timestamp t1 = new Timestamp(today+oneDay);
		Timestamp t2 = new Timestamp(today+(2*oneDay));
		Timestamp t3 = new Timestamp(today+(3*oneDay));
		Timestamp t4 = new Timestamp(today+(4*oneDay));
		
		items.add(new Item(1, "1", 5, MoneyPlanner.ONCE, t1, 0, 0, 0, null));
		items.add(new Item(2, "2", -5, MoneyPlanner.ONCE, t2, 0, 0, 0, null));
		items.add(new Item(3, "3", 10, MoneyPlanner.ONCE, t3, 0, 0, 0, null));
		
		mp = new MoneyPlan(items, 0, new Date());
		assertEquals(10f, mp.getAmountAt(t4));
		
		Map<Date, Float> amounts = mp.getAmountsUntil(t4);
		for(Date d : amounts.keySet()){
			Log.i("map",d+"->"+amounts.get(d));
		}
	}

	public void testDaily() throws Exception {
		ArrayList<Item> items = new ArrayList<Item>();
		long oneDay = (long) 1000.0 * 60 * 60 * 24;
		long today = System.currentTimeMillis();
		Timestamp t4 = new Timestamp(today+(4*oneDay));
		Timestamp t0 = new Timestamp(today);
		
		items.add(new Item(1, "1", 10, MoneyPlanner.PERIODICALLY, t0, MoneyPlanner.DAILY, 0, 0, null));
		
		mp = new MoneyPlan(items, 0, t0);
		Log.i("junit - amount at t4", ""+mp.getAmountAt(t4));
		assertEquals(40f, mp.getAmountAt(t4));
	}
}
